package MyGO.controller;

import MyGO.Data.GlobalData;
import MyGO.Form.TrackForm;
import MyGO.property.CheckPro;
import MyGO.service.ICheackProService;
import MyGO.service.impl.CheckProServiceImpl;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class CheckResultViewController {
    @Setter
    private Stage myStage;
    @Setter
    private TableViewController tableViewController;

    @FXML
    private Label PIDW;
    @FXML
    private Label PageW;
    @FXML
    private Label PgenderW;
    @FXML
    private Label PnameW;
    @FXML
    private TableColumn<CheckPro, String> IDCloumn;
    @FXML
    private TableColumn<CheckPro, String> checkNameCloumn;
    @FXML
    private TableColumn<CheckPro, Number> codeCloumn;
    @FXML
    private TableColumn<CheckPro, String> priceCloumn;
    @FXML
    private TableColumn<CheckPro, String> specCloumn;
    @FXML
    private TableColumn<CheckPro, String> statusCloumn;
    @FXML
    private TextField tf_aim;
    @FXML
    private TextField tf_checkDoctor;
    @FXML
    private TextField tf_checkPart;
    @FXML
    private TextField tf_remark;
    @FXML
    private TextField tf_time;
    @FXML
    private TextField tf_checkTime;
    @FXML
    private TextField tf_check_result;
    @FXML
    private TableView<CheckPro> tv_CheckPro;

    private List<CheckPro> checkPros = new ArrayList<>();
    private ICheackProService cheackProService = new CheckProServiceImpl();

    @FXML
    public void initialize() {
        PnameW.setText(GlobalData.trackForm.getName());
        PIDW.setText(GlobalData.trackForm.getId());
        PageW.setText(String.valueOf(GlobalData.trackForm.getPatientInfoForm().getYear()));
        PgenderW.setText(GlobalData.trackForm.getPatientInfoForm().getGender());
        tf_time.setText(GlobalData.trackForm.getCheckForm().getCreatTime());
        tf_checkDoctor.setText("检查部门");
        tf_checkPart.setText(GlobalData.trackForm.getCheckForm().getCheckPart());
        tf_aim.setText(GlobalData.trackForm.getCheckForm().getAim());
        tf_remark.setText(GlobalData.trackForm.getCheckForm().getRemark());
        tf_check_result.setText(GlobalData.trackForm.getCheckForm().getCheckResult());
//        System.out.println(GlobalData.trackForm.getCheckForm().getCheckResult());
        tf_checkTime.setText(GlobalData.trackForm.getCheckForm().getFinishTime());
//        System.out.println(GlobalData.trackForm.getCheckForm().getFinishTime());

        List<String> CheckProID = GlobalData.trackForm.getCheckForm().getCheckProIDs();
        HashMap<String, CheckPro> IDToCHeckPro = cheackProService.getAllCheckPro();
        HashMap<String, String> isPayMent = GlobalData.trackForm.getCheckForm().getIsPayMent();

        for (String ID : CheckProID) {
            checkPros.add(IDToCHeckPro.get(ID));
        }

        IDCloumn.setCellValueFactory(new PropertyValueFactory<>("id"));
        codeCloumn.setCellValueFactory(cellData ->
                new SimpleIntegerProperty(tv_CheckPro.getItems().indexOf(cellData.getValue()) + 1));
        checkNameCloumn.setCellValueFactory(new PropertyValueFactory<>("name"));
        specCloumn.setCellValueFactory(new PropertyValueFactory<>("specific"));
        priceCloumn.setCellValueFactory(new PropertyValueFactory<>("priceStr"));

        tv_CheckPro.getItems().addAll(checkPros);
    }


    @FXML
    void tv_ClickCheckProReleased(MouseEvent event) {

    }

    @FXML
    void tv_searchCheckProReleased(KeyEvent event) {

    }

}
